package com.wsoft.system.controller;

import com.github.pagehelper.PageInfo;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import com.wsoft.system.entity.SysMemberFileEntity;
import com.wsoft.system.query.member.file.SysMemberFileInsertQuery;
import com.wsoft.system.query.member.file.SysMemberFileListQuery;
import com.wsoft.system.query.member.file.SysMemberFileUpdateQuery;
import com.wsoft.system.service.ISysMemberFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 用户个人图片表 Controller
 *
 * @Author Z001
 * @Date 2025-03-06 01:28:06
 */
@RestController
@Tag(name = "用户个人图片")
@RequestMapping("/sys/member/file")
public class SysMemberFileController {

    @Resource
    private ISysMemberFileService sysMemberFileService;

    @Operation(summary = "用户个人图片-分页查询", description = "用户个人图片 -分页查询")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody @Valid SysMemberFileListQuery query) {
        PageInfo<SysMemberFileEntity> page = sysMemberFileService.listSysMemberFile(query);
        return ResponseResult.success(ResponsePage.restPage(page));
    }

    @Operation(summary = "用户个人图片-详情", description = "用户个人图片-详情")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(sysMemberFileService.getInfo(id));
    }

    @Operation(summary = "新增-用户个人图片", description = "新增-用户个人图片")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid SysMemberFileInsertQuery query) {
        boolean b =  sysMemberFileService.insertSysMemberFile(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "更新-用户个人图片", description = "更新-用户个人图片")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid SysMemberFileUpdateQuery query) {
        boolean b =  sysMemberFileService.updateSysMemberFile(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "删除-用户个人图片",description = "删除-用户个人图片")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = sysMemberFileService.delete(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
}
